<template>
  <div class="card">
    <div class="common-left-title">征信基本信息</div>
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="auto"
      require-asterisk-position="right">
        <el-form-item
          label="申请企业近24个月内是否存在单笔贷款连续3个月逾期"
          prop="creditMonth" label-width="auto">
          <el-select
            v-model="ruleForm.creditMonth"
            placeholder="请选择"
            style="width: 100px;">
            <el-option
              v-for="item in creditOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label="申请企业征信在近24个月内是否存在累计6次贷款逾期"
          prop="creditNumber" label-width="auto">
          <el-select
            v-model="ruleForm.creditNumber"
            placeholder="请选择"
            style="width: 100px;">
            <el-option
              v-for="item in creditOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-table
          v-if="ruleForm.creditNumber"
          :data="tableData"
          border size="small"
          style="width: 600px;">
          <el-table-column prop="label" width="180" />
          <el-table-column label="近24个月历史逾期记录">
            <template #default="{ row }">
              <span>{{ row.historyValue }}</span>
            </template>
          </el-table-column>
          <el-table-column label="当前逾期情况">
            <template #default="{ row }">
              <span>{{ row.currentValue }}</span>
            </template>
          </el-table-column>
        </el-table>
    </el-form>
  </div>
</template>

<script setup>
const ruleForm = reactive({
  // 征信逾期-近24个月内是否存在单笔贷款连续3个月
  creditMonth: true,
  // 征信逾期-近24个月内是否存在累计6次
  creditNumber: true,
})
const rules = reactive({

})

// 征信预期枚举
const creditOptions = reactive([
  { label: '是', value: true },
  { label: '否', value: false }
])

const tableData = reactive([
  {
    label: '逾期笔数',
    historyValue: '3笔',
    currentValue: '0笔'
  },
  {
    label: '逾期金额合计',
    historyValue: '¥5,000',
    currentValue: '¥0'
  },
  {
    label: '最长逾期时长（月）',
    historyValue: '2个月',
    currentValue: '0个月'
  }
])

// 表单校验
const ruleFormRef = ref(null)
function validateForm() {
  return new Promise((resolve, reject) => {
    ruleFormRef.value.validate(valid => {
      if (valid) {
        resolve(ruleForm)
      }
    })
  })
}

defineExpose({
  validateForm
})
</script>

<style lang="scss" scoped>
.el-form{
  margin-left: 20px;
}
</style>
